#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 12000010;

struct dsu {
  int fa[maxn];
  int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
  }
} d1, d2;

int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int n, m, k, dis[maxn], vis[maxn], px[maxn], py[maxn];
pii s, t;
string a[maxn];
deque<pii> q;

int id(int x, int y) {
  return (x - 1) * (m + 1) + y;
}

void del(int x, int y) {
  d1.fa[id(x, y)] = d1.find(id(x + 1, y));
  d2.fa[id(x, y)] = d2.find(id(x, y + 1));
}

int main() {
  freopen("stamp.in", "r", stdin);
  freopen("stamp.out", "w", stdout);
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n >> m >> k >> s.fi >> s.se >> t.fi >> t.se;
  rep (i, 1, n + 1) rep (j, 1, m + 1) px[id(i, j)] = i, py[id(i, j)] = j;
  rep (i, 1, n + 1) rep (j, 1, m + 1) d1.fa[id(i, j)] = id(i, j), d2.fa[id(i, j)] = id(i, j);
  rep (i, 1, n) cin >> a[i], a[i] = "#"s + a[i];
  rep (i, 1, (n + 1) * (m + 1)) dis[i] = 1e9;
  dis[id(s.fi, s.se)] = 0, q.push_back(s);
  while (!q.empty()) {
    int x = q.front().fi, y = q.front().se;
    q.pop_front();
    if (vis[id(x, y)]) continue;
    vis[id(x, y)] = 1;
    rep (k, 0, 3) {
      int tx = x + dx[k], ty = y + dy[k];
      if (tx < 1 || tx > n || ty < 1 || ty > m || a[tx][ty] == '#') continue;
      if (dis[id(x, y)] < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)], q.push_front(pii(tx, ty));
    }
    {
      int lp = max(1, x + 1 - k), rp = min(n, x + k - 1), ty = max(1, y - k);
      for (int tx = px[d1.find(id(lp, ty))]; tx <= rp; tx = px[d1.find(id(tx + 1, ty))]) {
        if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
        del(tx, ty);
        if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
      }
    }
    // rep (dx, 1 - k, k - 1) {
      // int ty = max(1, y - k), tx = x + dx;
      // if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
      // if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
    // }
    {
      int lp = max(1, x + 1 - k), rp = min(n, x + k - 1), ty = min(m, y + k);
      for (int tx = px[d1.find(id(lp, ty))]; tx <= rp; tx = px[d1.find(id(tx + 1, ty))]) {
        if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
        del(tx, ty);
        if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
      }
    }
    // rep (dx, 1 - k, k - 1) {
      // int ty = min(m, y + k), tx = x + dx;
      // if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
      // if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
    // }
    {
      int lp = max(1, y + 1 - k), rp = min(m, y + k - 1), tx = max(1, x - k);
      for (int ty = py[d2.find(id(tx, lp))]; ty <= rp; ty = py[d2.find(id(tx, ty + 1))]) {
        if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
        del(tx, ty);
        if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
      }
    }
    // rep (dy, 1 - k, k - 1) {
      // int tx = max(1, x - k), ty = y + dy;
      // if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
      // if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
    // }
    {
      int lp = max(1, y + 1 - k), rp = min(m, y + k - 1), tx = min(n, x + k);
      for (int ty = py[d2.find(id(tx, lp))]; ty <= rp; ty = py[d2.find(id(tx, ty + 1))]) {
        if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
        del(tx, ty);
        if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
      }
    }
    // rep (dy, 1 - k, k - 1) {
      // int tx = min(n, x + k), ty = y + dy;
      // if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
      // if (dis[id(x, y)] + 1 < dis[id(tx, ty)]) dis[id(tx, ty)] = dis[id(x, y)] + 1, q.push_back(pii(tx, ty));
    // }
  }
  int ans = dis[id(t.fi, t.se)];
  rep (dx, -k, k) rep (dy, -k, k) {
    if (abs(dx) + abs(dy) == 2 * k) continue;
    int tx = t.fi + dx, ty = t.se + dy;
    if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
    chkmn(ans, dis[id(tx, ty)] + 1);
  }
  cout << ans << '\n';
}